In a previous lesson, we learned how to listen for right click event on the browser Windows Web contents
and now also knowing how to build menus, we can use the combination of these two topics to create custom
context menus for our app.
This lesson being a short add on to the previous lesson, rather than covering a new module, specifically
the menu classis pop up method or instant's method as in the previous lesson.
I'll start by creating a very basic menu, this time being a context menu rather than our app's main
menu.
I'll assign to context menu require the menu module, which will again build from a template using the
bolt from template static method.
Past this, an array with a new menu item labeled item one and a second item to.
We now have a menu to show when a user right clicks.
Meaning the next step will be to listen for that right click event.
We do this on the Windows Web contents.
So in create windows say main window dot web content on context menu being that right click event,
the event callback providing us the event object e.
And in this event we can now show our new menu, this context menu by calling context menu dot pop up.
You can again pass in the window instance on which to create this pop up or context menu, but omitting
it will simply default to the window on which the event fired.
Save this right.
Click somewhere on the Windows Web content and there we get this pop up of our context menu with those
two menu items appearing wherever we right click.
At the moment, these menu items don't have any purpose, but as we saw in the previous lesson, assigning
click handlers or roles is fairly simple.
For example, change item two to have a role of edit menu, I'll add a text area to the content again.
Save both of these files.
Close the dev tools for a bit of extra space, adding some text, which I can now right click on to
select and under edit defined by the edit menu roll, we now see all the expected edit menu items like,
for example, copy.
Then pist.
Undue and so on, everything working as expected with minimal coding.
That's it for this lesson, a very simple but important concept for a fully featured native app.